// 将包名修改为 tools 以保持一致
package tools

import (
	"context"
	"log"

	"github.com/jackc/pgx/v5/pgxpool"
)

var db *pgxpool.Pool

func init() {
	connStr := "postgres://postgres:Supos1304@192.168.10.115:15432/kernel"

	config, _ := pgxpool.ParseConfig(connStr)
	config.MaxConns = 10
	config.MinConns = 1
	config.MinIdleConns = 1

	var err error
	db, err = pgxpool.NewWithConfig(context.Background(), config)
	if err != nil {
		log.Fatalf("Unable to create connection pool: %v\n", err)
	}

	// test connection
	err = db.Ping(context.Background())
	if err != nil {
		log.Fatalf("Unable to connect database: %v\n", err)
	}

	log.Println("Connected to database")
}
